package com.yanqu.road.server.manger.config;

import com.yanqu.road.entity.task.UserTaskData;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.logic.thread.ThreadTaskManger;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.thread.ALiPayTask;
import com.yanqu.road.server.logic.thread.MeiTuanTask;
import com.yanqu.road.utils.executor.GeneralTask;
import com.yanqu.road.utils.string.StringUtils;

import java.util.concurrent.atomic.AtomicInteger;

public class ALiPayReportMgr extends TempMgr{

    private static ThreadTaskManger threadTaskManger;

    private static AtomicInteger taskId = new AtomicInteger(2);

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        if (null == threadTaskManger) {
            threadTaskManger = new ThreadTaskManger(1, "ALiPayReportMgr");
        }
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

    @Override
    public boolean save() {
        return super.save();
    }

    /**
     * 支付宝任务上报
     */
    public static void alipayReport(GamePlayer player, String appExt, BaseCondition baseCondition, UserTaskData task){
        if (StringUtils.isNullOrEmpty(ChannelConfig.ALIPAY_REPORT_URL)) {
            return;
        }
        addTask(new ALiPayTask(player, appExt, baseCondition, task));
    }

    public static void addTask(GeneralTask task) {
        threadTaskManger.addTask(taskId.getAndIncrement(), task);
    }

    /**
     * 美团任务上报
     */
    public static void meiTuanReport(GamePlayer player, String appExt, BaseCondition baseCondition, UserTaskData task){
        if (StringUtils.isNullOrEmpty(ChannelConfig.MEI_TUAN_REPORT_URL)) {
            return;
        }
        addTask(new MeiTuanTask(player, appExt, baseCondition, task));
    }
}